package com.wxboot.game.eliminate.modules.service.strategy;

import com.wxboot.game.eliminate.base.BombAreaPoint;
import com.wxboot.game.eliminate.config.JellyConstant;

public abstract class AbstractBombStrategy implements BombStrategy {

    protected void registerBombStrategy(BombStrategy bombStrategy) {
        BombStrategyRegistry.registerBombStrategy(this.getJellyType(), bombStrategy);
    }

    protected BombAreaPoint generateBombing(int leftUpRow, int leftUpCol,
                                            int rightDownRow, int rightDownCol) {
        leftUpRow = this.recompute(leftUpRow);
        leftUpCol = this.recompute(leftUpCol);
        rightDownRow = this.recompute(rightDownRow);
        rightDownCol = this.recompute(rightDownCol);

        return new BombAreaPoint(leftUpRow, leftUpCol, rightDownRow, rightDownCol);
    }

    protected int recompute(int point) {
        if (point > JellyConstant.CELL_NUM - 1) {
            return JellyConstant.CELL_NUM - 1;
        }

        if (point < 0) {
            return 0;
        }

        return point;
    }

}
